package com.gzzz.bean.impl;

import com.gzzz.bean.Input;

import java.io.*;

/**
 * className: LocalFileInput
 * Package : com.gzzz.bean.impl
 * Description:
 *
 * @Author gzzz
 * @Create 2023/12/5 0:36
 * @Version 1.0
 */

/**
 * 实现读取本地文件路径下的文件
 */
public class LocalFileInput implements Input {
    private String filePath;

    public LocalFileInput() {
    }

    public LocalFileInput(String filePath) {
        this.filePath = filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    @Override
    public InputStream read() {
        FileInputStream fis = null;
        //创建相关的字节流
        try {
            File file = new File(filePath);
            fis = new FileInputStream(file);
            return fis;
        } catch (FileNotFoundException e) {
            System.out.println(filePath);
            System.out.println("路径输入错误或文件不存在！");
            e.printStackTrace();
        }
        return null;
    }
}

